//
//  BeeGroupHeaderView.m
//  FbeeAPP
//
//  Created by dev-m on 2018/3/7.
//  Copyright © 2018年 mohao. All rights reserved.
//

#import "BeeGroupHeaderView.h"
#import "BeeGroupListObj.h"
#import "BeePhotoImageView.h"
#import "FbeeCommitBtn.h"

#import "UIImageView+WebCache.h"

@interface BeeGroupHeaderView()
{
    BeeGroupListObj *dataObj;
    
    BeePhotoImageView *photo;
    UILabel *title;
    UILabel *info;
}
@end

@implementation BeeGroupHeaderView

-(instancetype)initWithFrame:(CGRect)frame obj:(BeeGroupListObj *)obj
{
    self = [super initWithFrame:frame];
    
    if (self) {
        dataObj = obj;
        [self buildView];
    }
    
    return self;
}

-(void)buildView
{
    //获取虚化背景
    [self getHeaderBg];
    
    //头像
    photo = [[BeePhotoImageView alloc] initWithFrame:CGRectMake(17, 0, 50, 50) imgUrl:dataObj.logoUrl photoStyle:BeePhotoDefaultStyle];
    photo.bottom = self.height - 18;
    [self addSubview:photo];
    
    //标题
    title = [UILabel makeLabel:^(TTLabelExtend *make) {
        make.setFrame(CGRectZero);
        make.addTextColor(COLOR_WHITE).addFont([UIFont systemFontOfSize:24.0f]);
        make.addText(dataObj.groupName);
        [make sizeToFit];
        make.height = 34;
        make.left = photo.right + 11;
        make.top = photo.top - 4;
        [self addSubview:make];
    }];
    
    info = [UILabel makeLabel:^(TTLabelExtend *make) {
        make.setFrame(CGRectZero);
        make.addFont([UIFont systemFontOfSize:14.0f]);
        make.addTextColor(COLOR_WHITE);
        if (dataObj.isReward) {
            make.addText(dataObj.groupRewardInfo);
        }
        else
        {
            make.addText(dataObj.groupInfo);
        }
        
        [make sizeToFit];
        if ((IPHONEWIDTH - title.left*2 - make.width) < 0) {
            make.width = IPHONEWIDTH - title.left*2;
        }
        make.height = 17;
        make.left = title.left;
        make.top = title.bottom;
        [self addSubview:make];
    }];
    
}

-(void)getHeaderBg
{
    //未虚化背景
    UIImageView *bgImg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.width, self.height)];
    //平铺
    [bgImg setContentScaleFactor:[[UIScreen mainScreen] scale]];
    bgImg.contentMode =  UIViewContentModeScaleAspectFill;
    bgImg.autoresizingMask = UIViewAutoresizingFlexibleHeight;
    bgImg.clipsToBounds  = YES;
    [bgImg sd_setImageWithURL:[NSURL URLWithString:dataObj.logoUrl]];
    [self addSubview:bgImg];
    
//    //背景虚化
//    UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight];
//    UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:effect];
//    effectView.frame = CGRectMake(0, 0, bgImg.width, bgImg.height);
//    [bgImg addSubview:effectView];
    
    //黑色遮盖
    UIView *black = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.width, self.height)];
    black.backgroundColor = [UIColor blackColor];
    black.alpha = 0.5;
    [self addSubview:black];
    
}

@end
